package com.tanhua.server.exception;

import com.tanhua.model.vo.ErrorResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/*
    统一异常处理器
 */
@ControllerAdvice//声明异常处理器
public class ExceptionAdvice {

    //编写异常处理方法
    @ExceptionHandler(Exception.class)//声明要处理哪些异常,不可以预知的异常
    public ResponseEntity handlerException(Exception e) {
        e.printStackTrace();
        ErrorResult vo = ErrorResult.error();
        return ResponseEntity.status(500).body(vo);
    }

    @ExceptionHandler(BusinessException.class)
    public ResponseEntity handlerBusinessException(BusinessException e){
         e.printStackTrace();
        ErrorResult vo = e.getVo();
        return ResponseEntity.status(500).body(vo);
    }
}
